#ifndef X38_H
#define X38_H

#include "common.h"

#include <string>

template <AllegroVersion version>
struct x38
{
    uint32_t t;
    uint32_t k;
    uint32_t next;
    uint32_t ptr1;
    char layer_name[20];
    uint32_t un1[7];
    
    uint32_t TAIL;
    operator x38<A_174>() const;
    static constexpr AllegroVersion versions[2] = {A_166, A_174};
    
    std::string s;
};

#if __cplusplus >= 202002L
template <AllegroVersion version> requires(version >= A_166)
struct x38<version>
{
    uint32_t t;
    uint32_t k;
    uint32_t next;
    uint32_t ptr1;
    uint32_t ptr;
    uint32_t un2;
    uint32_t un1[7];
    COND_FIELD(version >= A_174, uint32_t, un3);

    uint32_t TAIL;
    operator x38<A_174>() const;
    static constexpr AllegroVersion versions[2] = {A_166, A_174};

    std::string s;
};
#else
template <> struct x38<A_166>
{
    uint32_t t;
    uint32_t k;
    uint32_t next;
    uint32_t ptr1;
    uint32_t ptr;
    uint32_t un2;
    uint32_t un1[7];

    uint32_t TAIL;
    operator x38<A_174>() const;
    static constexpr AllegroVersion versions[2] = {A_166, A_174};

    std::string s;
};
template <> struct x38<A_172> : x38<A_166> {};

template <> struct x38<A_174>
{
    uint32_t t;
    uint32_t k;
    uint32_t next;
    uint32_t ptr1;
    uint32_t ptr;
    uint32_t un2;
    uint32_t un1[7];
    uint32_t un3;

    uint32_t TAIL;
    operator x38<A_174>() const;
    static constexpr AllegroVersion versions[2] = {A_166, A_174};

    std::string s;
};
#endif

static_assert(sizeof_until_tail<x38<A_160>>() == 64);
static_assert(sizeof_until_tail<x38<A_165>>() == 64);
static_assert(sizeof_until_tail<x38<A_166>>() == 52);

#endif // X38_H
